package any.xpath;

import java.util.Iterator;

import any.ImmutableAny;

public class AnythingElement {

	private AnythingElement parent;
	private String name;
	private ImmutableAny any;

	public AnythingElement(AnythingElement parent, String name, ImmutableAny any) {
		this.parent = parent;
		this.name = name;
		this.any = any;
	}

	public AnythingElement getParent() {
		return this.parent;
	}

	public String getName() {
		return this.name;
	}

	public ImmutableAny getAny() {
		return this.any;
	}
	
	@Override
	public String toString() {
		return "parent: '" + parent.name + "' / name: '" + name + "' / any: " + any;
	}

	public static class Itr implements Iterator<AnythingElement> {
		private AnythingElement parent;
		private Iterator<ImmutableAny> iterator;
		private int i = 0;
		
		public Itr(AnythingElement parent, Iterator<ImmutableAny> iterator) {
			this.parent = parent;
			this.iterator = iterator;
		}

		public boolean hasNext() {
			return this.iterator.hasNext();
		}

		public AnythingElement next() {
			return new AnythingElement(parent, String.valueOf(i++), this.iterator.next());
		}

		public void remove() {
			throw new UnsupportedOperationException();
		}
	}

}
